package com.tao.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.tao.springcloud.service.OrderHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName OrderController
 * @Author HETAO
 * @Date 2020/5/10 17:31
 */
@RestController
@RequestMapping("consumer")
@DefaultProperties(defaultFallback = "paymentGlobal") //默认降级执行的方法
@Slf4j
public class OrderController {
    @Resource
    private OrderHystrixService orderHystrixService;

    @GetMapping("pyment/ok")
    public String paymentInfoOK(@RequestParam("id") Integer id)  {
        return orderHystrixService.paymentInfoOK(id);
    }

    @GetMapping("pyment/timeout/{id}")
   /* @HystrixCommand(fallbackMethod = "paymentInfoTimeOutHandler",commandProperties = @HystrixProperty(
            name = "execution.isolation.thread.timeoutInMilliseconds",value="1500"
    ))*/
   @HystrixCommand
    public String paymentInfoTimeOut(@PathVariable("id") Integer id)  {
        return orderHystrixService.paymentInfoTimeOut(id);
    }

    public String paymentInfoTimeOutHandler(@PathVariable("id") Integer id) {
        return "请求超时或出现异常";
    }
    public String paymentGlobal() {
        return "global 默认后备";
    }
}
